package zm.irc.message.send;

import zm.irc.util.Base64Util;

public class IrcLogonSaslMessage implements IrcSendMessage {
    private String nick;
    private String userName;
    private String realName;

    /**
     * sasl's account
     */
    private String authId;

    /**
     * sasl's assword
     */
    private String passwd;

    private String host;
    private String server;

    

    public String getAuthId() {
        return authId;
    }

    public void setAuthId(String authId) {
        this.authId = authId;
    }

    public void setPwd(String passwd){
        this.passwd = passwd;
    }

    public String getNick() {
        return nick;
    }
    public void setNick(String nick) {
        this.nick = nick;
    }
    public String getUserName() {
        return userName;
    }
    public void setUserName(String userName) {
        this.userName = userName;
    }
    public String getRealName() {
        return realName;
    }
    public void setRealName(String realName) {
        this.realName = realName;
    }
    public String getHost() {
        return host;
    }
    public void setHost(String host) {
        this.host = host;
    }
    public String getServer() {
        return server;
    }
    public void setServer(String server) {
        this.server = server;
    }
    @Override
    public String getMessage() {
        StringBuilder msgStr = new StringBuilder();
        msgStr.append("CAP LS 302\r\n");
        msgStr.append("NICK " + this.getNick() + "\r\n");
        msgStr.append(String.format("USER %s %s %s :%s\r\n",this.getUserName(),this.getHost(),this.getServer(),this.getRealName()));
        msgStr.append("CAP REQ :sasl\r\n");
        msgStr.append("AUTHENTICATE PLAIN\r\n");

        String authString = String.format("%s%s%s%s%s",this.getAuthId(),'\0',this.getAuthId(),'\0',this.passwd);
        msgStr.append("AUTHENTICATE " + Base64Util.encode(authString) + "\r\n");
        msgStr.append("CAP END\r\n");
        return msgStr.toString();
    }

   
}
